package com.aaa.project.zhreport.controller;

import com.aaa.framework.web.controller.BaseController;
import com.aaa.framework.web.domain.AjaxResult;
import com.aaa.framework.web.page.TableDataInfo;
import com.aaa.project.zhreport.controller.dto.YwfxDataApplyProcessReqDTO;
import com.aaa.project.zhreport.controller.dto.YwfxDataApplyQueryDTO;
import com.aaa.project.zhreport.controller.dto.YwfxDataApplyReqDTO;
import com.aaa.project.zhreport.controller.dto.YwfxDataApplyResDTO;
import com.aaa.project.zhreport.service.YwfxDataApplyService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author baibin
 * @version 1.0
 * @date 2025/4/9 10:06
 * @description YwfxDataApplyController
 */
@RestController
@RequestMapping("/data/apply")
public class YwfxDataApplyController extends BaseController {

    @Resource
    private YwfxDataApplyService service;

    /**
     * 申请接口
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/add",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public AjaxResult apply(@RequestPart("request") YwfxDataApplyReqDTO request,
                            @RequestPart(value = "file", required = false) MultipartFile file,
                            HttpServletRequest httpRequest) {
        request.setAttachment(file);
        service.apply(request, httpRequest);
        return success();
    }

    /**
     * 查询接口
     *
     * @param request
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(YwfxDataApplyQueryDTO request) {
        startPage();
        List<YwfxDataApplyResDTO> list = service.list(request);
        return getDataTable(list);
    }

    /**
     * 审批接口
     *
     * @param request
     * @return
     */
    @PostMapping("/approve")
    public AjaxResult approve(@RequestBody YwfxDataApplyProcessReqDTO request) {
        return AjaxResult.success(null, service.approve(request));
    }

    /**
     * 详情接口
     *
     * @param id
     * @return
     */
    @GetMapping("/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id) {
        return success(service.detail(id));
    }

    /**
     * 预生成sql接口
     * 
     * @param request
     * @return
     */
    @PostMapping("/generate/sql")
    public AjaxResult generateSql(@RequestBody YwfxDataApplyReqDTO request) {
        return AjaxResult.success(null, service.generateSql(request));
    }

    // 预执行sql接口
    @PostMapping("/pre/execute/sql")
    public AjaxResult preExecuteSql(@RequestBody YwfxDataApplyReqDTO request) {
        service.preExecuteSql(request);
        return success();
    }

    /**
     * 查询工单号接口
     *
     * @return
     */
    @GetMapping("/queryOrderList")
    public AjaxResult queryOrderList(String userId, String orderTime) {
        AjaxResult ajax = AjaxResult.success();
        String result = service.queryOrderList(userId, orderTime);
        ajax.put("orderList",result);
        return ajax;
    }

}
